package leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * @Classname LengthOfLongestSubstring
 * @Author happytaohaha
 * @Date 2020/3/8
 * @Description 快慢指针
 */
public class LengthOfLongestSubstring_0003 {
    public static int lengthOfLongestSubstring(String s) {
        int len = s.length();
        Set<Character> set = new HashSet<Character>();
        int i = 0,j = 0, ans = 0;
        while(i < len && j < len){
            if( !set.contains(s.charAt(j))){
                set.add(s.charAt(j++));
                ans = Math.max(ans, j-i);
            }else{
                set.remove(s.charAt(i++));
            }

        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("asdasdea"));
    }

}
